package com.test.byteDance;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Byte2019_2 {
    int planNum = 0;

    public int arrestPlan(int[] ints, int d) {
        if (ints.length < 3) {
            return 0;
        }
        dfs(ints, d, new boolean[ints.length], 0, new ArrayList<>());
        return planNum;
    }

    public void dfs(int[] ints, int d, boolean[] visit, int index, List<Integer> res) {
        if (judgeNum(res, d) && res.size() == 3) {
            planNum++;
            return;
        }
        if (!judgeNum(res, d)) {
            return;
        }
        for (int i = index; i < ints.length; i++) {
            if (!visit[i]) {
                visit[i] = true;
                res.add(ints[i]);
                dfs(ints, d, visit, i + 1, res);
                res.remove(res.size() - 1);
                visit[i] = false;
            }
        }
    }

    public boolean judgeNum(List<Integer> res, int d) {
        if (res.size() > 1) {
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            for (Integer re : res) {
                min = Math.min(min, re);
                max = Math.max(max, re);
            }
            return (max - min) <= d;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int D = scanner.nextInt();
        int[] ints = new int[N];

        for (int i = 0; i < N; i++) {
            ints[i] = scanner.nextInt();
        }
        Byte2019_2 byte2019_2 = new Byte2019_2();
        System.out.println(byte2019_2.arrestPlan(ints, D));
    }

}
